package com.module.utils;

import com.module.listen.OnlineSession;
import com.module.listen.SessionListener;

import java.util.Iterator;
import java.util.List;

/**
 * @author: Mr.Zhong
 * @create: 2018-07-03 19:00
 * @description:
 **/
public class SessionUtil {

    /**
    * 描述: 检测用户是否在线
    * @param
    * @param username
     * @return
    * @Author: Mr.Zhong
    * @Date: 2018/7/3
    */
    public static Boolean checkedOnline(Object username){
        List sessions = SessionListener.getSessions();
        if (sessions.size()!=0) {
            OnlineSession onlineSession = null;
            Iterator it = sessions.iterator();
            int count = 0;
            while (it.hasNext()) {
                count++;
                onlineSession = (OnlineSession) it.next();
                if (onlineSession.getLoginId().equals(username)) {
                   return true;
                } else {
                   return false;
                }
            }
        }else {
            return false;
        }
        return true;
    }


}
